package com.bgamq.springboot.tokencontroller;

import cn.hutool.core.util.StrUtil;
import com.bgamq.springboot.api.AutoIdempotent;
import com.bgamq.springboot.service.TestService;
import com.bgamq.springboot.token.TokenService;
import com.bgamq.springboot.util.ServerResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class BusinessController {


    @Resource
    private TokenService tokenService;

    @Resource
    private TestService testService;


    @PostMapping("/get/token")
    public String  getToken(){
        String token = tokenService.createToken();
        if (StrUtil.isNotEmpty(token)) {
            return token;
        }
        return StrUtil.EMPTY;
    }


    @AutoIdempotent
    @PostMapping("/test/Idempotence")
    public String testIdempotence() {
        ServerResponse serverResponse = testService.idempotentTestTest();
        String msg = serverResponse.getMsg();
        if (StrUtil.isNotEmpty(msg)) {
           /* ResultVo successResult = ResultVo.getSuccessResult(businessResult);
            return JSONUtil.toJsonStr(successResult);*/
            return msg;
        }
        return StrUtil.EMPTY;
    }
}
